#include <stdio.h>
#include <stdlib.h>
#include "tree.h"
#include "sqstack.h"

#if 0 //非递归遍历二叉树
int main(void)
{
	char * str = "ABC##DE##F##G#H##";
	BinaryTree tree;

	Init(&tree,'#');

	//Create1(&tree, &str);
	Create2(&tree, &str);

	printf("非递归前序遍历结果：");
	_PreOrder(tree.root);
	printf("非递归中序遍历结果：");
	_InOrder(tree.root);
	//_PostOrder(tree.root);

	exit(EXIT_SUCCESS);
}
#endif

#if 0
int main(void)
{
	//char *str = "ABC##DE##F##G#H##";
	char *str = "ABC##D##G#H##";
	char sech = 'H';  //被查找的结点
	BinaryTree tree;

	Init(&tree, '#');

	// Create1(&tree);
	Create2(&tree, &str);

	printf("前序遍历结果：");
	PreOrder(&tree);
	printf("中序遍历结果：");
	InOrder(&tree);
	printf("后序遍历结果：");
	PostOrder(&tree);
	printf("层次序遍历结果：");
	LevelOrder(tree.root);

	printf("Size of Tree = %d\n", Size(&tree));
	printf("Height of Tree = %d\n", Height(tree.root));

	BinaryTreeNode *p = Search(tree.root, sech);
	if (p == NULL)
		printf("不存在\n");
	else
		printf("找到 %c 结点,地址为 %p\n", sech, p);

	BinaryTreeNode *parent = Parent(tree.root, p);
	if (parent == NULL)
		printf("找不到\n");
	else
		printf("parent is %c\n", parent->data);

	// printf("left child is %c\n", LeftChild(p)->data);
	// printf("right child is %c\n", RightChild(p)->data);

	if (Empty(&tree))
		printf("为空\n");
	else
		printf("非空\n");

	BinaryTree newtree;
	Init(&newtree, '#');
	Copy(tree.root, &newtree.root);
	
	PreOrder(&newtree);
	InOrder(&newtree);
	PostOrder(&newtree);
	Clear(&tree.root);
	if (tree.root == NULL)
		printf("树清空\n");

	return 0;
}
#endif

#if 1
int main(void)
{
	//char * str = "ABC##DE##F##G#H##";
	//char *str = "ABC##D##G#H##";
	char *str = "AB##C##";
	BinaryTree tree;

	Init(&tree,'#');
	Create1(&tree, &str);

	PreOrder(&tree);
	InOrder(&tree);
	PostOrder(&tree);
	printf("\n");

	LevelOrder(tree.root);
	printf("\n");

	_PreOrder2(tree.root);
	_InOrder(tree.root);

	return 0;
}
#endif